package mulMan.gui.view;

import java.awt.event.ActionListener;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;

import mulMan.domain.PlaylistModel;

public class PlaylistView extends JFrame  implements Observer {

	private static final long serialVersionUID = 4874267953096856903L;
	
	private PlaylistModel playlist;
	JMenuItem menuItemAddNewAudioFile;
	JMenuItem menuItemExit;
	JPanel audioFilesView = null;
	
	public PlaylistModel getPlaylist() {
		return playlist;
	}
	public void setPlaylist(PlaylistModel playlist) {
		this.playlist = playlist;
	}
	public JPanel getAudioFilesView() {
		return audioFilesView;
	}
	public void setAudioFilesView(JPanel audioFilesView) {
		this.audioFilesView = audioFilesView;
		getContentPane().add(audioFilesView);
	    setVisible(true);
	}
	public PlaylistView(PlaylistModel playlist) {
		this.playlist = playlist;
		this.playlist.addObserver(this);
		
		initView();
	    initFields();
	    
	}

	public void update(Observable o, Object arg) {
		if (arg == "list") {
			((AudioFilesView)audioFilesView).resetList();
		}
	}

	public void initView() {
		JPanel panel = new JPanel();
	    getContentPane().add(panel);
	    panel.setLayout(null);
	    
		setTitle("Playlist window");
	    setSize(600, 400);
	    setResizable(false);
	    setLocationRelativeTo(null);
	    setDefaultCloseOperation(EXIT_ON_CLOSE);
	    
	    initMenu();
	}
	
	private void initMenu() {
		JMenuBar menuBar = new JMenuBar();
		
		JMenu menuFile = new JMenu("File");
		menuBar.add(menuFile);
		
		menuItemAddNewAudioFile = new JMenuItem("Add New Audio File");
		menuFile.add(menuItemAddNewAudioFile);
		
		menuItemExit = new JMenuItem("Exit");
		menuFile.add(menuItemExit);
		
		setJMenuBar(menuBar);
	}
	
	public void initFields() {
	}
	
	public void addAddNewAudioFileListener(ActionListener anafl) {
		menuItemAddNewAudioFile.addActionListener(anafl);
    }
	public void addExitListener(ActionListener el) {
		menuItemExit.addActionListener(el);
    }
}
